﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using SfcorpDLL.biz;
using GT.ORM;
using TT.Common;
using Billing.ety;
using Billing;

namespace Sfcorp.form
{
    public partial class frmAgyBnsTY : DevExpress.XtraEditors.XtraForm
    {
        bizAgyBns bzAgyBns;
        etyChargeDtl eyChrgDtl;
        bool hadOneSuccess = false;
        TT.Common.DataProcType status = DataProcType.NEW;
        etyChargeDtl eyBillPara = new etyChargeDtl();

        public frmAgyBnsTY(etyChargeDtl chrgDtl, etyBillParams iBillRq, type_view_bill tyBill, DataTable dtAmount, FactoryBill ibzBill)
        {
            InitializeComponent();

            //F2 添加费用
            eyChrgDtl = chrgDtl;
            eyChrgDtl.CASH_FLAG = "1";
            txtQty.Text = eyChrgDtl.QTY;
        }

        private void btOK_Click(object sender, EventArgs e)
        {
            TT.Common.formProcess.GetFormEntity(eyChrgDtl, cGroupControl2);

            eyChrgDtl.ITEM = "TY_I";
            eyChrgDtl.CHARGE_SEQ = "";
            bool succ = bzAgyBns.Billing_Add_ChargeDtl(eyChrgDtl);
            TT.HelpInfo.MsgBox.ShowSuccessFailBox(succ);
            if (succ) this.Close();
        }

        private void frmAgyBnsTY_Load(object sender, EventArgs e)
        {
            bzAgyBns = new bizAgyBns(global.basSysPara);
        }

        private void txtPrice_TextChanged(object sender, EventArgs e)
        {
            ResetAmount();
        }
        private void ResetAmount()
        {
            decimal qty;
            decimal qtyPer;
            decimal price;
            if (!decimal.TryParse(txtQty.Text, out qty) || !decimal.TryParse("1", out qtyPer)
                || !decimal.TryParse(txtPrice.EditValue.ToString().Trim(), out price))
                return;
            txtAmount.Text = (qty * qtyPer * price).ToString();
        }

        private void txtPrice_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btOK.Focus();
            }
        }
    }
}